using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PharmacyDomain;
using ShivamEMR.Model.DataInterfaces.PharmacyDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Pharmacy.Models;

namespace ShivamEMR.Web.Areas.Pharmacy.Controllers
{   
    public class DrugCategoryController : Controller
    {
		private readonly IDrugCategoryRepository drugcategoryRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DrugCategoryController() 
        {
            drugcategoryRepository = Registry.RepositoryFactory.GetDrugCategoryRepository();
        }

        public DrugCategoryController(IDrugCategoryRepository drugcategoryRepository)
        {
			this.drugcategoryRepository = drugcategoryRepository;
        }

        //
        // GET: /DrugCategory/

        public ViewResult Index()
        {
         //   return View(drugcategoryRepository.AllIncluding(drugcategory => drugcategory.DrugGenerics));
            return View(drugcategoryRepository.All);
        }

        //
        // GET: /DrugCategory/Details/5

        public ViewResult Details(int id)
        {
            return View(drugcategoryRepository.Find(id));
        }

        //
        // GET: /DrugCategory/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /DrugCategory/Create

        [HttpPost]
        public ActionResult Create(DrugCategory drugcategory)
        {
            if (ModelState.IsValid) {
                drugcategoryRepository.InsertOrUpdate(drugcategory);
                drugcategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /DrugCategory/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(drugcategoryRepository.Find(id));
        }

        //
        // POST: /DrugCategory/Edit/5

        [HttpPost]
        public ActionResult Edit(DrugCategory drugcategory)
        {
            if (ModelState.IsValid) {
                drugcategoryRepository.InsertOrUpdate(drugcategory);
                drugcategoryRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /DrugCategory/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(drugcategoryRepository.Find(id));
        }

        //
        // POST: /DrugCategory/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var dc = drugcategoryRepository.Find(id);
            drugcategoryRepository.Delete(dc);
            drugcategoryRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

